﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GcmpCollaborationInterface.h"
#include "GbmpQuickCast.h"

namespace gcmp
{
    /// \brief 唯一编辑Id查询返回值
    /// \param Ok 表示返回状态，是否成功
    /// \param UniqueEditId 唯一编辑Id, 低22位有效
    struct GCMP_COLLABORATION_INTERFACE_EXPORT QueryUniqueEditIdResponse
    {
        QueryUniqueEditIdResponse() { }
        QueryUniqueEditIdResponse(bool isOk, uint32_t uEId) : Ok(isOk), UniqueEditId(uEId)
        {
        }
        bool Ok = false;
        uint32_t UniqueEditId = 0;
    };

    /// \brief 唯一编辑Id提供者
    class GCMP_COLLABORATION_INTERFACE_EXPORT IUniqueEditIdProvider
    {
        DEFINE_CAST_BASE(gcmp::IUniqueEditIdProvider)
    public:
        /// \brief 获取唯一编辑Id
        /// \param datasetSubId 工作单元项目内编号
        /// \param datasetId 工作单元Id
        /// \return QueryUniqueEditIdResponse
        virtual QueryUniqueEditIdResponse QueryUniqueEditId(const uint32_t& datasetSubId, const std::wstring& datasetId) = 0;

        /// \brief 析构函数
        virtual ~IUniqueEditIdProvider() {};
    };
    
    /// \brief 构件级协同ElementId前缀中unique edit id管理器
    class GCMP_COLLABORATION_INTERFACE_EXPORT IUniqueEditIdManager
    {
        DEFINE_CAST_BASE(gcmp::IUniqueEditIdManager)
    public:
        /// \brief 获取实例
        static IUniqueEditIdManager * Get();

        /// \brief 注册唯一编辑编号提供者, 注册时机文档创建、打开前
        /// \param provider 新提供者
        /// \return 返回旧的提供者
        virtual IUniqueEditIdProvider * RegisterUniqueEditIdProvider(IUniqueEditIdProvider * provider) = 0;

        /// \brief 查询UniqueEditId 数据
        /// \param datasetSubId 工作单元项目内编号
        /// \param datasetId 工作单元Id
        /// \param pErrorMessage 相关错误提示
        /// \return QueryUniqueEditIdResponse
        virtual QueryUniqueEditIdResponse QueryUniqueEditId(const uint32_t& datasetSubId, const std::wstring& datasetId, std::wstring * pErrorMessage) = 0;

        /// \brief 获取当前唯一编辑Id
        /// \return QueryUniqueEditIdResponse
        virtual const QueryUniqueEditIdResponse& GetCurrentUniqueEditId() const = 0;

        /// \brief 析构函数
        virtual ~IUniqueEditIdManager();
    protected:
        static IUniqueEditIdManager* m_instance;
    };
}
